package com.lanou3g.ptp.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 创建人: 武奇
 * 创建事件: 2019/8/29
 */
public class RegexUtils {

    public static String[] findImgUrlsInHtml(String content) {
        String regex = "<img.*src\\s*=\\s*(.*?)[^>]*?>";
        Pattern p = Pattern.compile(regex);
        Matcher matcher = p.matcher(content);
        List<String> list = new ArrayList<>();

        while (matcher.find()) {
            String img = matcher.group();
            Matcher m = Pattern.compile("src\\s*=\\s*\"?(.*?)(\"|>|\\s+)").matcher(img);
            while (m.find()) {
                list.add(m.group(1));
            }
        }
        return list.toArray(new String[0]);
    }

}
